<template>
	<div>
		<cl-crud @load="onLoad">
			<template #slot-filter>
				<!-- <div class="nav base-flex">
					<div class="nav-li">
						<span>券金额大于</span>
						<el-input-number
							v-model="filterSelectVal.amount"
							controls-position="right"
							@change="
								val =>
									refresh({
										startCouponMoney: val
									})
							"
							:min="0"
							size="mini"
						></el-input-number>
					</div>
					<div class="nav-li">
						<span>月销量大于</span>
						<el-input-number
							v-model="filterSelectVal.monthSales"
							controls-position="right"
							@change="
								val =>
									refresh({
										startSale: val
									})
							"
							:min="0"
							size="mini"
						></el-input-number>
					</div>
					<div class="nav-li">
						<span>是否9.9包邮</span>
						<el-select
							class="el-select"
							placeholder="请选择"
							size="mini"
							v-model="filterSelectVal.isNine"
							@change="
								val =>
									refresh({
										isNine: val
									})
							"
						>
							<el-option label="全部" value></el-option>
							<el-option label="是" :value="1"></el-option>
							<el-option label="否" :value="0"></el-option>
						</el-select>
					</div>
					<div class="nav-li">
						<span>是否抖好货</span>
						<el-select
							class="el-select"
							placeholder="请选择"
							size="mini"
							v-model="filterSelectVal.isDouGoods"
							@change="
								val =>
									refresh({
										isDhh: val
									})
							"
						>
							<el-option label="全部" value></el-option>
							<el-option label="是" :value="1"></el-option>
							<el-option label="否" :value="0"></el-option>
						</el-select>
					</div>
					<div class="nav-li">
						<filterClass
							@change="
								val =>
									refresh({
										cid: val
									})
							"
						></filterClass>
					</div>
					<div class="nav-li">
						<filterGstatus
							@change="
								val =>
									refresh({
										gStatus: val
									})
							"
						></filterGstatus>
					</div>
					<div class="nav-li">
						<span>是否置顶</span>
						<el-select
							class="el-select"
							placeholder="请选择"
							size="mini"
							v-model="filterSelectVal.isRecommended"
							@change="
								val =>
									refresh({
										isRecommended: val
									})
							"
						>
							<el-option label="全部" value></el-option>
							<el-option label="是" :value="1"></el-option>
							<el-option label="否" :value="0"></el-option>
						</el-select>
					</div>
				</div>-->
				<div class="nav base-flex">
					<div class="nav-li">
						<div>
							<span>榜单</span>
							<el-select
								placeholder="请选择"
								size="mini"
								v-model="params.type"
								@change="val => refresh({type: val})"
								style="width: 150px"
							>
								<el-option :label="item.label" :value="item.value" v-for="(item, i) in rankType" :key="i"></el-option>
							</el-select>
						</div>
					</div>
					<div class="nav-li">
						<!-- <filterClass
							@change="
								val =>
									refresh({
										cid: val
									})
							"
						></filterClass>-->

						<div>
							<span>分类</span>
							<el-select
								class="el-select"
								placeholder="请选择"
								size="mini"
								v-model="params.cid"
								@change="val => refresh({cid: val})"
							>
								<el-option label="全部" value></el-option>
								<el-option
									:label="item.label"
									:value="item.value"
									v-for="(item, i) in typeOptions2"
									:key="i"
								></el-option>
							</el-select>
						</div>
					</div>
					<!-- <div class="nav-li">
						<filterGstatus
							@change="
								val =>
									refresh({
										status: val
									})
							"
						></filterGstatus>
					</div>-->
				</div>
			</template>
			<template #slot-add>
				<el-button type="danger" size="mini" @click="addGoods()">录入商品</el-button>
			</template>
			<!-- <template #slot-setSort="{scope}">
				<p class="setsort" @click="setGoodsort(scope.row)">修改</p>
			</template>-->
			<!-- <template #slot-setBillion="{scope}">
				<p class="setsort" @click="setGoodInfo(scope.row)">设置百亿补贴</p>
			</template> -->
			<!-- <template #slot-setTime="{scope}">
				<p class="setsort" @click="setRushInfo(scope.row)">设置限时抢购</p>
			</template>-->
			<!-- <template #slot-zero="{scope}">
				<p class="setsort" @click="setZero(scope.row)">设置0元购</p>
			</template>-->
			<template #slot-delete="{scope}">
				<delBtn @del="crud.delete(scope.row)"></delBtn>
			</template>

			<template #table-column-goodInfo="{scope}">
				<!-- <good-info :item="scope.row"></good-info> -->
				<jd-good-info :item="scope.row"></jd-good-info>
			</template>
			<template #table-column-isRecommended="{scope}">
				<div>
					<el-tag v-if="scope.row.isRecommended == 1" type="success">是</el-tag>
					<el-tag type="info" v-else>否</el-tag>
				</div>
			</template>
			<template #table-column-couponInfo="{scope}">
				<!-- <coupon-info :item="scope.row"></coupon-info> -->
				<jd-coupon-info :item="scope.row"></jd-coupon-info>
			</template>
			<template #table-column-isDHh="{scope}">
				<div>
					<el-tag v-if="scope.row.isDhh == 1" type="success">是</el-tag>
					<el-tag type="info" v-else>否</el-tag>
				</div>
			</template>
			<template #table-column-gStatus="{scope}">
				<div>
					<el-tag v-if="scope.row.gStatus == 1" type="success">正常</el-tag>
					<el-tag type="info" v-if="scope.row.gStatus == 2">已下架</el-tag>
				</div>
			</template>
			<template #table-column-isNine="{scope}">
				<div>
					<el-tag v-if="scope.row.isNine == 1" type="success">是</el-tag>
					<el-tag type="info" v-else>否</el-tag>
				</div>
			</template>
			<template #table-column-platform="{scope}">
				{{
				scope.row.source | dict_platform
				}}
			</template>
		</cl-crud>

		<cl-form ref="cl-form"></cl-form>
		<cl-form ref="cl-form2"></cl-form>
	</div>
</template>

<script>
import JdGoodInfo from './components/list/jd-good-info';
import JdCouponInfo from './components/list/jd-coupon-info';
import goodInfo from './components/list/good-info';
import couponInfo from './components/list/coupon-info';
import searchCounpon from './components/list/searchCoupon';
import filterClass from './components/filterClass';
// import filterGstatus from './components/filterGstatus';
import { platform } from '@/dict/index';
import { Type_TLJ } from '@/dict/index';
import moment from 'moment';
import store from 'store';

export default {
	data() {
		return {
			crud: null,
			platform: platform,
			platformIndex: '',
			mail: '',
			dou: '',
			filterSelectVal: {
				amount: 0, //劵金额
				monthSales: 0, //月销量
				isNine: '',
				isDouGoods: '',
				isRecommended: 0
			},
			enterGoodsInfo: {},
			accountList: [], // 淘宝联盟列表
			fromList: [], // 平台列表
			typeOptions: [],
			typeOptions2: [],
			perfaceValue_GoodInfo: 0,
			perfaceValue_Rush: 0,
			perfaceValue_Zero: 0,
			goodsTitle: '正在获取中',
			actime: [],
			goodsTypeMemory: '',
			params: {
				cid: '',
				type: 1
			},
			rankType: [
				{
					value: 1,
					label: '实时榜'
				}
			]
		};
	},
	components: {
		goodInfo,
		couponInfo,
		// eslint-disable-next-line
		searchCounpon,
		filterClass,
		JdGoodInfo,
		JdCouponInfo
		// filterGstatus
	},
	created() {
		this.actime = [
			moment(new Date().getTime() + 86400000).format('YYYY-MM-DD 00:00:00'),
			moment(new Date().getTime() + 172800000).format('YYYY-MM-DD 00:00:00')
		];
		this.taobaoAccountTlj();
		this.getType();
		this.getType2();
		this.platForm();
	},
	methods: {
		// 获取百亿补贴类型
		// 100
		getType() {
			// 获取百万补贴商品分类
			this.$service.goodsMenagement.specialClassify
				.page({
					page: 1,
					size: 60,
					sort: 'asc',
					order: 'level',
					specialType: 100
				})
				.then(res => {
					var temp = res.list;
					var target = [];
					for (var i = 0; i < temp.length; i++) {
						target[i] = { label: temp[i].mainName, value: temp[i].floorId };
					}
					this.typeOptions = target;
				});
		},
		// 101
		getType2() {
			// 获取京东商品分类
			this.$service.goodsMenagement.specialClassify
				.page({
					page: 1,
					size: 60,
					sort: 'asc',
					order: 'level',
					specialType: 102
				})
				.then(res => {
					var temp = res.list;
					var target = [];
					for (var i = 0; i < temp.length; i++) {
						target[i] = { label: temp[i].mainName, value: temp[i].cid };
					}
					this.typeOptions2 = target;
				});
		},
		// 获取联盟账号
		async taobaoAccountTlj() {
			let list = await this.$service.goodsMenagement.taobaoAccountTlj.userAccountList({
				isBwbt: 1
			});
			list = list.map(item => {
				return {
					label: item.accountName,
					value: item.accountId
				};
			});
			this.accountList = list;
			// console.log('this.accountList', this.accountList)
		},
		// 获取平台账号
		platForm() {
			this.$service.common.userAppList().then(res => {
				let list = res.map(el => {
					return {
						label: el.name,
						value: el.key
					};
				});
				this.fromList = list;
			});
		},
		submitForm(formData) {
			this.crud.setForm('data', formData);
			this.crud.submit();
		},
		setGoodsort(item) {
			console.log(item);

			const self = this;
			let app = this.$refs['cl-form'].open({
				props: {
					'label-width': '120px',
					width: '570px',
					center: true,
					'custom-class': 'custom-class-dialog-mini'
				},
				items: [
					{
						prop: 'pic',
						label: '商品主图：',
						span: 24,
						value: item.pic,
						component: {
							name: 'cl-upload'
						}
					},
					{
						prop: 'title',
						label: '商品标题',
						span: 24,
						value: item.title,
						component: {
							name: 'el-input',
							attrs: {
								size: 'mini'
							}
						}
					},
					{
						prop: 'ysqLevel',
						label: '商品排序',
						span: 24,
						value: item.ysqLevel ? item.ysqLevel : 100,
						component: {
							name: 'ysqlevel-input',
							data() {
								return {
									value2: 0
								};
							},
							props: {
								value: [String, Number]
							},
							mounted() {
								this.value2 = this.value;
							},
							methods: {
								input(e) {
									this.$emit('input', e);
								}
							},
							render() {
								return (
									<div style="display:flex">
										<el-input-number
											controls-position="right"
											min={1}
											max={100000}
											onInput={this.input}
											v-model={this.value2}></el-input-number>
										<span style="color:red;margin-left:10px">
											* 序号越大，排序越靠前
										</span>
									</div>
								);
							}
						},
						rules: [{ required: true, message: '排序不能为空', trigger: 'blur' }]
					},
					{
						prop: 'gStatus',
						label: '是否上架',
						span: 12,
						value: item.gStatus,
						component: {
							name: 'el-input-number1',
							attrs: {
								'controls-position': 'right',
								min: 1,
								max: 10000
							},
							data() {
								return {
									value2: 1
								};
							},
							props: {
								value: [String, Number]
							},
							methods: {
								change(e) {
									console.log(e);
									this.$emit('input', e);
								}
							},
							mounted() {
								this.value2 = this.value;
							},
							render() {
								return (
									<el-radio-group onChange={this.change} v-model={this.value2}>
										<el-radio label={1}>上架</el-radio>
										<el-radio label={0}>下架</el-radio>
									</el-radio-group>
								);
							}
						},
						rules: [{ required: true, message: '免单总数不能为空', trigger: 'blur' }]
					},
					{
						prop: 'isRecommended',
						props: {
							'label-width': '120px'
						},
						label: '是否开启首页置顶',
						span: 13,
						value: item.isRecommended == 1 ? true : false,
						component: {
							name: 'el-switch',
							on: {
								change(val) {
									if (val) {
										app.setData('items[prop:recommendSort].hidden', false);
									} else {
										app.setData('items[prop:recommendSort].hidden', true);
									}
								}
							}
						}
					},
					{
						prop: 'recommendSort',
						label: '商品置顶排序',
						span: 24,
						hidden: item.isRecommended == 1 ? false : true,
						value: item.recommendSort || 1,
						component: {
							name: 'recommendSort-input',
							data() {
								return {
									value2: 0
								};
							},
							props: {
								value: [String, Number]
							},
							mounted() {
								this.value2 = this.value;
							},
							methods: {
								input(e) {
									this.$emit('input', e);
								}
							},
							render() {
								return (
									<div style="display:flex">
										<el-input-number
											controls-position="right"
											min={1}
											max={5}
											onInput={this.input}
											v-model={this.value2}></el-input-number>
										<span style="color:red;margin-left:10px">
											* 首页置顶(序号越小，排序越靠前)
										</span>
									</div>
								);
							}
						},
						rules: [{ required: true, message: '排序不能为空', trigger: 'blur' }]
					}
				],
				on: {
					submit({ data, close }) {
						self.$service.goodsMenagement.goods
							.updateGoods({
								...data,
								isRecommended: data.isRecommended ? 1 : 0,
								id: item.gid
							})
							.then(() => {
								self.$message({
									message: '设置成功',
									type: 'success'
								});
								self.crud.refresh();
								close();
								return;
							})
							.catch(err => {
								self.$message.error(err);
							});
					}
				}
			});
		},
		// 设置百亿补贴
		setGoodInfo(item) {
			const self = this;
			const subsidyData = store.get('set-subsidy') || {};

			const app = this.$refs['cl-form2'].open({
				props: {
					labelWidth: '120px',
					center: true,
					'custom-class': 'custom-class-dialog',
					width: '750px'
				},
				// items: [
				// 	{
				// 		prop: 'title',
				// 		label: '商品标题',
				// 		span: 24,
				// 		component: {
				// 			name: 'el-input',
				// 			attrs: {
				// 				size: 'mini'
				// 			}
				// 		}
				// 	},
				// 	{
				// 		prop: 'accountIds',
				// 		label: '账号',
				// 		span: 13,
				// 		value: subsidyData.accountIds || [self.accountList[0].value],
				// 		// value: '',
				// 		component: {
				// 			name: 'el-select',
				// 			options: self.accountList,
				// 			attrs: {
				// 				placeholder: '请选择账号'
				// 			},
				// 			props: {
				// 				multiple: true
				// 			}
				// 		},
				// 		rules: {
				// 			required: true,
				// 			message: '账号不能为空'
				// 		}
				// 	},
				// 	{
				// 		prop: 'campaignType',
				// 		label: '创建类型',
				// 		span: 10,
				// 		value: 2,
				// 		component: {
				// 			name: 'el-select',
				// 			attrs: {
				// 				placeholder: '请选择'
				// 			},
				// 			props: {
				// 				clearable: true
				// 			},
				// 			options: Type_TLJ
				// 		},
				// 		rules: {
				// 			required: true,
				// 			message: '创建类型不能为空'
				// 		}
				// 	},
				// 	{
				// 		prop: 'gid',
				// 		label: '商品ID',
				// 		span: 10,
				// 		value: item.gid,
				// 		component: {
				// 			name: 'el-input',
				// 			attrs: {
				// 				placeholder: '请选择'
				// 			},
				// 			props: {}
				// 		}
				// 	},
				// 	{
				// 		prop: 'url',
				// 		props: {
				// 			labelWidth: '0px'
				// 		},
				// 		component: {
				// 			name: 'search-counpon',
				// 			props: {
				// 				item: Object
				// 			},
				// 			attrs: {
				// 				item
				// 			},
				// 			mounted() {
				// 				console.log('item', this.item);
				// 				this.$refs['real'].ruleForm.url = this.item.link;
				// 				this.$refs['real'].ruleForm.couponUrl = this.item.couponUrl;
				// 				this.$refs['real'].ruleForm.gid = this.item.gid;
				// 				this.$refs['real'].submitForm('form');
				// 			},
				// 			methods: {
				// 				input(e) {
				// 					this.$emit('input', e);
				// 				},
				// 				Goodsinfo(e) {
				// 					self.enterGoodsInfo = e;
				// 					self.goodsTitle = e.title.substring(0, 10);
				// 				},
				// 				perface(e) {
				// 					self.perfaceValue_GoodInfo = e;
				// 				},
				// 				onSelectPic(url) {
				// 					console.log(url);
				// 					app.setForm('pic', url);
				// 				}
				// 			},
				// 			render() {
				// 				return (
				// 					<searchCounpon
				// 						ref="real"
				// 						onInput={this.input}
				// 						onGoodsInfo={this.Goodsinfo}
				// 						onperface={this.perface}
				// 						on-select-pic={this.onSelectPic}
				// 						item={self.enterGoodsInfo}
				// 						type={3}></searchCounpon>
				// 				);
				// 			}
				// 		},
				// 		rules: [{ required: true, message: '请先检索商品', trigger: 'blur' }]
				// 	},
				// 	{
				// 		prop: 'floorId',
				// 		label: '商品分类',
				// 		span: 12,
				// 		// value: subsidyData.floorId || self.goodsTypeMemory,
				// 		value: item.floorId,
				// 		component: {
				// 			name: 'el-select',
				// 			attrs: {
				// 				placeholder: '请选择'
				// 			},
				// 			props: {
				// 				clearable: true
				// 			},
				// 			options: self.typeOptions,
				// 			on: {
				// 				change: id => {
				// 					self.goodsTypeMemory = id;
				// 					console.log(id);
				// 				}
				// 			}
				// 		},
				// 		rules: {
				// 			required: true,
				// 			message: '商品分类不能为空'
				// 		}
				// 	},
				// 	{
				// 		prop: 'tljMoney',
				// 		label: '淘礼金金额：',
				// 		component: {
				// 			name: 'mdMoney_c',
				// 			data() {
				// 				return {
				// 					value2: 0
				// 				};
				// 			},
				// 			methods: {
				// 				Change() {
				// 					this.$emit('input', self.perfaceValue_GoodInfo);
				// 					if (
				// 						this.value2 >=
				// 						(self.enterGoodsInfo.endPrice -
				// 							self.enterGoodsInfo.hzQuanOver) *
				// 							0.8
				// 					) {
				// 						self.$message.error('淘礼金金额不能大于商品券后价的80%');
				// 					}
				// 				}
				// 			},

				// 			render() {
				// 				return (
				// 					<div style="display:flex">
				// 						<el-input-number
				// 							max={
				// 								Number(
				// 									self.enterGoodsInfo.endPrice -
				// 										self.enterGoodsInfo.hzQuanOver
				// 								) * 0.8 || 0
				// 							}
				// 							step={0.01}
				// 							min={1}
				// 							v-model={self.perfaceValue_GoodInfo}
				// 							onfocus={this.Change}
				// 							onChange={this.Change}></el-input-number>
				// 						<div style="margin-left:10px">
				// 							到手价格￥
				// 							<span style="color:red">
				// 								{(
				// 									parseFloat(self.enterGoodsInfo.endPrice || 0) -
				// 									(self.perfaceValue_GoodInfo
				// 										? self.perfaceValue_GoodInfo
				// 										: 0) -
				// 									(self.enterGoodsInfo.hzQuanOver || 0)
				// 								).toFixed(2)}
				// 							</span>
				// 							元
				// 						</div>
				// 					</div>
				// 				);
				// 			}
				// 		}
				// 	},
				// 	{
				// 		prop: 'tljName',
				// 		label: '淘礼金名称',
				// 		value: self.goodsTitle,
				// 		component: {
				// 			name: 'tljName-input',
				// 			attrs: {
				// 				placeholder: '请输入名称',
				// 				clearable: true,
				// 				maxlength: 10
				// 			},
				// 			methods: {
				// 				Change() {
				// 					this.$emit('input', self.goodsTitle);
				// 				}
				// 			},
				// 			render() {
				// 				return (
				// 					<el-input
				// 						v-model={self.goodsTitle}
				// 						onChange={this.Change}
				// 						onfocus={this.Change}></el-input>
				// 				);
				// 			}
				// 		},
				// 		rules: [
				// 			{
				// 				required: true,
				// 				message: '淘礼金名字不能为空'
				// 			},
				// 			{
				// 				min: 5,
				// 				max: 10,
				// 				message: '淘礼金名字在5 ~ 10个字符之间'
				// 			}
				// 		]
				// 	},
				// 	{
				// 		prop: 'total',
				// 		label: '活动商品个数：',
				// 		span: 8,
				// 		value: parseInt(Math.random() * (10000 - 5000 + 1) + 5000, 10),
				// 		component: {
				// 			name: 'el-input-number',
				// 			attrs: {
				// 				'controls-position': 'right',
				// 				min: 1,
				// 				max: 10000
				// 			}
				// 		},
				// 		rules: [
				// 			{
				// 				required: true,
				// 				message: '请输入活动商品数量',
				// 				trigger: 'blur'
				// 			}
				// 		]
				// 	},
				// 	{
				// 		prop: 'time',
				// 		label: '活动时间：',
				// 		value: subsidyData.time || self.actime,
				// 		span: 16,
				// 		component: {
				// 			name: 'el-date-picker',
				// 			attrs: {
				// 				type: 'datetimerange',
				// 				'value-format': 'yyyy-MM-dd HH:mm:ss'
				// 			}
				// 		},
				// 		rules: [
				// 			{
				// 				required: true,
				// 				message: '请选择活动时间',
				// 				trigger: 'blur'
				// 			}
				// 		]
				// 	},
				// 	{
				// 		prop: 'ysqLevel',
				// 		label: '商品排序：',
				// 		value: 100,
				// 		component: {
				// 			name: 'ysqlevels',
				// 			data() {
				// 				return {
				// 					ysqLevel: 100
				// 				};
				// 			},
				// 			props: {
				// 				value: [String, Number]
				// 			},
				// 			mounted() {
				// 				this.ysqLevel = this.value;
				// 			},
				// 			methods: {
				// 				input(e) {
				// 					this.$emit('input', e);
				// 				}
				// 			},
				// 			render() {
				// 				return (
				// 					<div>
				// 						<el-input-number
				// 							v-model={this.ysqLevel}
				// 							controls-position="right"
				// 							onInput={this.input}
				// 							min={1}
				// 							max={10000}></el-input-number>
				// 						<span style="color:#999999;margin-left:10px">
				// 							序号越大，排序越靠前
				// 						</span>
				// 					</div>
				// 				);
				// 			}
				// 		}
				// 	},
				// 	{
				// 		prop: 'defNum',
				// 		label: '初始领取数量：',
				// 		value: parseInt(Math.random() * 2000) + 4000,
				// 		span: 13,
				// 		component: {
				// 			name: 'el-input-number'
				// 		}
				// 	},
				// 	{
				// 		prop: 'status',
				// 		label: '商品状态：',
				// 		value: 1,
				// 		component: {
				// 			name: 'g_radio',
				// 			data() {
				// 				return {
				// 					value2: 1
				// 				};
				// 			},
				// 			props: {
				// 				value: [String, Number]
				// 			},
				// 			mounted() {
				// 				this.value2 = Number(this.value || 1);
				// 			},
				// 			methods: {
				// 				change(e) {
				// 					this.$emit('input', e);
				// 				}
				// 			},
				// 			render() {
				// 				return (
				// 					<el-radio-group onChange={this.change} v-model={this.value2}>
				// 						<el-radio label={1}>上架</el-radio>
				// 						<el-radio label={0}>下架</el-radio>
				// 					</el-radio-group>
				// 				);
				// 			}
				// 		}
				// 	},
				// 	{
				// 		prop: 'top',
				// 		label: '是否置顶：',
				// 		value: 1,
				// 		component: {
				// 			name: 'z_radio',
				// 			data() {
				// 				return {
				// 					value2: 1
				// 				};
				// 			},
				// 			props: {
				// 				value: [String, Number]
				// 			},
				// 			mounted() {
				// 				this.value2 = Number(this.value || 1);
				// 			},
				// 			methods: {
				// 				change(e) {
				// 					this.$emit('input', e);
				// 				}
				// 			},
				// 			render() {
				// 				return (
				// 					<el-radio-group onChange={this.change} v-model={this.value2}>
				// 						<el-radio label={1}>是</el-radio>
				// 						<el-radio label={0}>否</el-radio>
				// 					</el-radio-group>
				// 				);
				// 			}
				// 		}
				// 	}
				// ],
				items: [
					{
						prop: 'skuImage',
						label: '商品主图：',
                        span: 24,
                        value: item.pic,
						component: {
							name: 'cl-upload'
						}
					},
					{
						prop: 'skuName',
						label: '商品标题',
						span: 24,
						component: {
							name: 'el-input',
							attrs: {
								size: 'mini',
								placeholder: '请输入商品标题'
							}
						}
					},
					{
						prop: 'url',
						props: {
							labelWidth: '0px'
						},
						// label: '优惠券链接：',
						component: {
							name: 'search-counpon',
							methods: {
								input(e) {
									this.$emit('input', e);
								},
								onCoupon(e) {
									self.selects.coupon = e;
								},
								onJmoney(e) {
									app.setForm('jljMoney', e);
								}
							},
							render() {
								return (
									<searchCounpon
										onInput={this.input}
										onCoupon={this.onCoupon}
										on-jmoney={this.onJmoney}
										item={self.enterGoodsInfo}></searchCounpon>
								);
							}
						},
						rules: [{ required: true, message: '请先检索商品', trigger: 'blur' }]
					},
					{
						label: '京礼金总数',
						prop: 'total',
						component: {
							name: 'el-input-number',
							props: {
								min: 50
							}
						},
						rules: {
							required: true,
							validator: (rule, value, callback) => {
								if (value % 50 == 0) {
									callback();
								} else {
									callback(new Error('京礼金数量需为50的整数倍'));
								}
							}
						}
					},
					{
						prop: 'type',
						label: '活动分类',
						component: {
							name: 'el-select',
							props: {
								placeholder: '商品分类',
								clearable: true
							},
							options: [
								{
									label: '零元购',
									value: '0'
								},
								{
									label: '限时抢购',
									value: '1'
								},
								{
									label: '新人专享',
									value: '2'
								},
								{
									label: '百亿补贴',
									value: '3'
								},
								{
									label: '大转盘',
									value: '4'
								}
							]
						},
						rules: [
							{
								required: true,
								message: '请选择商品分类',
								trigger: 'blur'
							}
						]
					},
					{
						label: '商品基数',
						prop: 'defNum',
						value: 0,
						component: {
							name: 'el-input-number',
							props: {}
						},
						rules: {
							required: true,
							message: '商品基数不能为空'
						}
					},
					{
						label: '京礼金金额',
						prop: 'jljMoney',
						component: {
							name: 'el-input-number'
						},
						rules: {
							required: true,
							message: '京礼金金额不能为空'
						}
					},
					{
						label: '活动时间',
						prop: '_date',
						value: [
							moment()
								.add(1, 'days')
								.format('YYYY-MM-DD 00:00:00'),
							moment()
								.add(1, 'days')
								.format('YYYY-MM-DD 23:59:59')
						],
						component: {
							name: 'el-date-picker',
							props: {
								'value-format': 'yyyy-MM-dd HH:mm:ss',
								type: 'datetimerange'
							}
						},
						rules: {
							required: true,
							message: '活动时间不能为空'
						}
					},
					{
						prop: 'level',
						label: '商品排序：',
						value: 100,
						component: {
							name: 'levels',
							data() {
								return {
									level: 100
								};
							},
							props: {
								value: [String, Number]
							},
							mounted() {
								this.level = this.value;
							},
							methods: {
								input(e) {
									this.$emit('input', e);
								}
							},
							render() {
								return (
									<div style="display:flex">
										<el-input-number
											v-model={this.level}
											controls-position="right"
											onInput={this.input}
											min={1}
											max={10000}></el-input-number>
										<span style="color:#999999;margin-left:10px">
											序号越大，排序越靠前
										</span>
									</div>
								);
							}
						}
					},
					{
						label: '使用有效日期',
						prop: 'effectiveDays',
						span: 12,
						value: 0,
						component: {
							name: 'el-input-number',
							props: {
								min: 1,
								max: 7
							}
						},
						rules: {
							required: true,
							message: '使用有效日期不能为空'
						}
					},
					{
						prop: 'status',
						label: '商品状态：',
						value: 1,
						component: {
							name: 'g_radio',
							data() {
								return {
									value2: 1
								};
							},
							props: {
								value: [String, Number]
							},
							mounted() {
								this.value2 = Number(this.value || 1);
							},
							methods: {
								change(e) {
									this.$emit('input', e);
								}
							},
							render() {
								return (
									<el-radio-group onChange={this.change} v-model={this.value2}>
										<el-radio label={1}>上架</el-radio>
										<el-radio label={0}>下架</el-radio>
									</el-radio-group>
								);
							}
						}
					},
					{
						label: '是否绑定spu',
						prop: 'isSpu',
						value: 0,
						component: {
							name: 'el-radio-group',
							options: [
								{
									label: '是',
									value: 1
								},
								{
									label: '否',
									value: 0
								}
							]
						}
					}
				],
				op: {
					visible: true,
					layout: ['confirm']
				},
				on: {
					load() {},
					submit({ data, close, done }) {
						// store.set('set-subsidy', {
						// 	floorId: data.floorId,
						// 	accountIds: data.accountIds,
						// 	time: data.time
						// });

						// data.quanMLink = self.enterGoodsInfo.quanMLink;
						// data.hzQuanOver = self.enterGoodsInfo.hzQuanOver;

                        // self.$service.goodsMenagement.mdGoods
                        // 新加的
                        const [startTime, endTime] = data._date || [];
						self.$service.jd.jdActivityGoods
							.add({
                                goodsNewType: item.floorId,
								...data,
								...data.url,
								type: 3,
								gid: item.gid,
								startTime: startTime,
								endTime: endTime,
								// tljType: 1,
								// accountIds: data.accountIds.join(',') // 改来改去
							})
							.then(() => {
								self.$message({
									message: '设置成功',
									type: 'success'
								});
								self.crud.refresh();
								close();
								return;
							})
							.catch(err => {
								self.$message.error(err);
								done();
							});
					}
				}
			});
		},
		// 设置限时抢购
		setRushInfo(item) {
			let self = this;
			const app = this.$refs['cl-form'].open({
				props: {
					labelWidth: '120px',
					center: true,
					'custom-class': 'custom-class-dialog'
				},
				items: [
					{
						prop: 'pic',
						label: '商品主图：',
						span: 24,
						component: {
							name: 'cl-upload'
						}
					},
					{
						prop: 'title',
						label: '商品标题',
						span: 24,
						component: {
							name: 'el-input',
							attrs: {
								size: 'mini'
							}
						}
					},
					{
						prop: 'appPlatforms',
						label: '平台',
						span: 13,
						value: [self.fromList[0].value],
						component: {
							name: 'el-select',
							options: self.fromList,
							attrs: {
								placeholder: '请选择平台',
								multiple: true
							},
							on: {
								change: id => {
									console.log(id);
								}
							}
						},
						rules: {
							required: true,
							message: '账号不能为空'
						}
					},
					{
						prop: 'gid',
						label: '商品ID',
						span: 10,
						value: item.gid,
						component: {
							name: 'el-input',
							attrs: {
								placeholder: '请选择'
							},
							props: {}
						}
					},
					{
						prop: 'url',
						props: {
							labelWidth: '0px'
						},
						component: {
							name: 'search-goods',
							props: {
								item: Object
							},
							attrs: {
								item
							},
							mounted() {
								this.$refs['real'].ruleForm.url = this.item.link;
								this.$refs['real'].ruleForm.couponUrl = this.item.couponUrl;
								this.$refs['real'].ruleForm.gid = this.item.gid;
								this.$refs['real'].submitForm('form');
							},
							methods: {
								input(e) {
									this.$emit('input', e);
								},
								Goodsinfo(e) {
									self.crud.setForm('mdMoney', e.preCommssion);
									self.enterGoodsInfo = e;
								},
								perface(e) {
									self.perfaceValue_Rush = e;
								},
								onSelectPic(url) {
									console.log(url);
									app.setForm('pic', url);
								}
							},
							render() {
								return (
									<searchCounpon
										ref="real"
										onInput={this.input}
										onGoodsInfo={this.Goodsinfo}
										onperface={this.perface}
										on-select-pic={this.onSelectPic}
										item={self.enterGoodsInfo}></searchCounpon>
								);
							}
						},
						rules: [{ required: true, message: '请先检索商品', trigger: 'blur' }]
					},

					{
						prop: 'mdMoney',
						label: '补贴金额：',
						value: self.perfaceValue_Rush,
						component: {
							name: 'mdMoney_c',
							data() {
								return {
									value2: 0
								};
							},
							methods: {
								Change() {
									this.$emit('input', self.perfaceValue_Rush);
									if (
										self.perfaceValue_Rush >=
										(self.enterGoodsInfo.endPrice -
											self.enterGoodsInfo.hzQuanOver) *
											0.8
									) {
										self.$message.error('淘礼金金额不能大于商品券后价的80%');
									}
								}
							},
							props: {
								value: [String, Number]
							},
							watch: {
								value(val) {
									console.log(val);
									self.perfaceValue_Rush = val;
								},
								'self.enterGoodsInfo.preCommssion'(val) {
									console.log(val);
								}
							},

							render() {
								return (
									<div style="display:flex">
										<el-input-number
											max={
												Number(
													self.enterGoodsInfo.endPrice -
														self.enterGoodsInfo.hzQuanOver
												) * 0.8 || 0
											}
											step={0.01}
											min={0}
											v-model={self.perfaceValue_Rush}
											onfocus={this.Change}
											onChange={this.Change}></el-input-number>
										<div style="margin-left:10px">
											到手价格￥
											<span style="color:red">
												{(
													parseFloat(self.enterGoodsInfo.endPrice || 0) -
													(self.perfaceValue_Rush
														? self.perfaceValue_Rush
														: 0) -
													(self.enterGoodsInfo.hzQuanOver || 0)
												).toFixed(2)}
											</span>
											元
										</div>
										<div style="margin-left:10px">
											佣金￥
											<span style="color:red">
												{self.enterGoodsInfo.preCommssion || 0}
											</span>
											元
										</div>
									</div>
								);
							}
						},
						rules: [{ required: true, message: '补贴金额必须大于1', trigger: 'blur' }]
					},
					{
						prop: 'total',
						label: '活动商品个数：',
						span: 8,
						value: parseInt(Math.random() * (10000 - 5000 + 1) + 5000, 10),
						component: {
							name: 'el-input-number',
							attrs: {
								'controls-position': 'right',
								min: 1,
								max: 10000
							},
							on: {
								change(val) {
									self.defNumMax = val;
								}
							}
						},
						rules: [
							{
								required: true,
								message: '请输入活动商品数量',
								trigger: 'blur'
							}
						]
					},
					{
						prop: 'time',
						label: '活动时间：',
						span: 8,
						value: moment().format('YYYY-MM-DD'),
						component: {
							name: 'el-date-picker',
							attrs: {
								type: 'date',
								'value-format': 'yyyy-MM-dd'
							}
						},
						rules: [
							{
								required: true,
								message: '请选择活动时间',
								trigger: 'blur'
							}
						]
					},
					{
						prop: '_time',
						props: {
							'label-width': '0px'
						},
						span: 6,
						component: {
							name: 'el-select-s',
							data() {
								return {
									value2: localStorage.getItem('timevalue'),
									options: []
								};
							},
							created() {
								this.$service.goodsMenagement.goods.flashTime().then(res => {
									this.options = res.map(e => {
										return {
											label: e.time,
											value: e.time
										};
									});
									if (this.value2) {
										this.change(this.value2);
									}
								});
							},
							methods: {
								change(e) {
									localStorage.setItem('timevalue', e);
									Array.prototype.getArrayIndex = function(obj) {
										for (var i = 0; i < this.length; i++) {
											if (this[i].value === obj) {
												return i;
											}
										}
										return -1;
									};
									let end = '';
									if (this.options.getArrayIndex(e) + 1 == this.options.length) {
										end = '24:00';
									} else {
										end = this.options[this.options.getArrayIndex(e) + 1].value;
									}
									this.$emit('input', {
										start: e,
										end
									});
								}
							},
							render() {
								return (
									<el-select onChange={this.change} v-model={this.value2}>
										{this.options.map(item => {
											return (
												<el-option
													label={item.label}
													value={item.value}></el-option>
											);
										})}
									</el-select>
								);
							}
						},
						rules: [
							{
								required: true,
								message: '请选择活动时间',
								trigger: 'blur'
							}
						]
					},
					{
						prop: 'ysqLevel',
						label: '商品排序：',
						value: 100,
						component: {
							name: 'ysqlevels',
							data() {
								return {
									ysqLevel: 100
								};
							},
							props: {
								value: [String, Number]
							},
							mounted() {
								this.ysqLevel = this.value;
							},
							methods: {
								input(e) {
									this.$emit('input', e);
								}
							},
							render() {
								return (
									<div>
										<el-input-number
											v-model={this.ysqLevel}
											controls-position="right"
											onInput={this.input}
											min={1}
											max={10000}></el-input-number>
										<span style="color:#999999;margin-left:10px">
											序号越大，排序越靠前
										</span>
									</div>
								);
							}
						}
					},
					{
						prop: 'defNum',
						label: '预设抢购：',
						value: 0,
						component: {
							name: 'defNum-s',
							data() {
								return {
									value2: 0
								};
							},
							props: {
								value: [String, Number]
							},
							mounted() {
								this.value2 = this.value;
							},
							methods: {
								input(e) {
									this.$emit('input', e);
								}
							},
							render() {
								return (
									<div>
										<el-input-number
											v-model={this.value2}
											controls-position="right"
											onInput={this.input}
											min={0}
											max={self.defNumMax}></el-input-number>
									</div>
								);
							}
						}
					},
					{
						label: '状态',
						prop: 'status',
						value: 1,
						component: {
							name: 'el-select',
							options: [
								{
									label: '上架',
									value: 1
								},
								{
									label: '下架',
									value: 2
								}
							]
						}
					}
				],
				op: {
					visible: true,
					layout: ['confirm']
				},
				on: {
					load() {},
					submit({ data, close }) {
						data.appPlatforms = data.appPlatforms.join(',');
						data.quanMLink = self.enterGoodsInfo.quanMLink;
						data.hzQuanOver = self.enterGoodsInfo.hzQuanOver;
						self.$service.goodsMenagement.mdGoods
							.add({
								...data,
								...data.url,
								gid: item.gid,
								type: 1,
								startTime: data.time + ' ' + data._time.start,
								endTime: data.time + ' ' + data._time.end
							})
							.then(() => {
								self.$message({
									message: '设置成功',
									type: 'success'
								});
								self.crud.refresh();
								close();
								return;
							})
							.catch(err => {
								self.$message.error(err);
							});
					}
				}
			});
		},
		// 设置零元购
		setZero(item) {
			let self = this;
			const app = this.$refs['cl-form'].open({
				props: {
					labelWidth: '120px',
					center: true,
					'custom-class': 'custom-class-dialog'
				},
				items: [
					{
						prop: 'title',
						label: '商品标题',
						span: 24,
						component: {
							name: 'el-input',
							attrs: {
								size: 'mini'
							}
						}
					},
					{
						prop: 'appPlatforms',
						label: '平台',
						span: 13,
						value: [self.fromList[0].value],
						component: {
							name: 'el-select',
							options: self.fromList,
							attrs: {
								placeholder: '请选择平台',
								multiple: true
							},
							on: {
								change: id => {
									console.log(id);
								}
							}
						},
						rules: {
							required: true,
							message: '账号不能为空'
						}
					},
					{
						prop: 'gid',
						label: '商品ID',
						span: 10,
						value: item.gid,
						component: {
							name: 'el-input',
							attrs: {
								placeholder: '请选择'
							},
							props: {}
						}
					},
					{
						prop: 'url',
						props: {
							labelWidth: '0px'
						},
						component: {
							name: 'search-counpon',
							props: {
								item: Object
							},
							attrs: {
								item
							},
							mounted() {
								this.$refs['real'].ruleForm.url = this.item.link;
								this.$refs['real'].ruleForm.couponUrl = this.item.couponUrl;
								this.$refs['real'].ruleForm.gid = this.item.gid;
								this.$refs['real'].submitForm('form');
							},
							methods: {
								input(e) {
									this.$emit('input', e);
								},
								Goodsinfo(e) {
									self.enterGoodsInfo = e;
								},
								perface(e) {
									self.perfaceValue_Zero = e;
								},
								onSelectPic(url) {
									console.log(url);
									app.setForm('pic', url);
								}
							},
							render() {
								return (
									<searchCounpon
										ref="real"
										onInput={this.input}
										onGoodsInfo={this.Goodsinfo}
										onperface={this.perface}
										on-select-pic={this.onSelectPic}
										item={self.enterGoodsInfo}></searchCounpon>
								);
							}
						},
						rules: [{ required: true, message: '请先检索商品', trigger: 'blur' }]
					},
					{
						prop: 'mdMoney',
						label: '补贴金额：',
						component: {
							name: 'mdMoney_c',
							data() {
								return {
									value2: 0
								};
							},
							methods: {
								Change() {
									this.$emit('input', self.perfaceValue_Zero);
									if (
										self.perfaceValue_Zero >=
										(self.enterGoodsInfo.endPrice -
											self.enterGoodsInfo.hzQuanOver) *
											0.8
									) {
										self.$message.error('淘礼金金额不能大于商品券后价的80%');
									}
								}
							},

							render() {
								return (
									<div style="display:flex">
										<el-input-number
											max={
												Number(
													self.enterGoodsInfo.endPrice -
														self.enterGoodsInfo.hzQuanOver
												) * 0.8 || 0
											}
											step={0.01}
											min={0}
											v-model={self.perfaceValue_Zero}
											onfocus={this.Change}
											onChange={this.Change}></el-input-number>
										<div style="margin-left:10px">
											到手价格￥
											<span style="color:red">
												{(
													parseFloat(self.enterGoodsInfo.endPrice || 0) -
													(self.perfaceValue_Zero
														? self.perfaceValue_Zero
														: 0) -
													(self.enterGoodsInfo.hzQuanOver || 0)
												).toFixed(2)}
											</span>
											元
										</div>
									</div>
								);
							}
						},
						rules: [{ required: true, message: '补贴金额必须大于1', trigger: 'blur' }]
					},
					{
						prop: 'total',
						label: '活动商品个数：',
						span: 8,
						value: parseInt(Math.random() * (10000 - 5000 + 1) + 5000, 10),
						component: {
							name: 'el-input-number',
							attrs: {
								'controls-position': 'right',
								min: 1,
								max: 10000
							}
						},
						rules: [
							{
								required: true,
								message: '请输入活动商品数量',
								trigger: 'blur'
							}
						]
					},
					{
						prop: 'time',
						label: '活动时间：',
						value: self.actime,
						span: 16,
						component: {
							name: 'el-date-picker',
							attrs: {
								type: 'datetimerange',
								'value-format': 'yyyy-MM-dd HH:mm:ss'
							}
						},
						rules: [
							{
								required: true,
								message: '请选择活动时间',
								trigger: 'blur'
							}
						]
					},
					{
						prop: 'ysqLevel',
						label: '商品排序：',
						value: 100,
						component: {
							name: 'ysqlevels',
							data() {
								return {
									ysqLevel: 100
								};
							},
							props: {
								value: [String, Number]
							},
							mounted() {
								this.ysqLevel = this.value;
							},
							methods: {
								input(e) {
									this.$emit('input', e);
								}
							},
							render() {
								return (
									<div>
										<el-input-number
											v-model={this.ysqLevel}
											controls-position="right"
											onInput={this.input}
											min={1}
											max={10000}></el-input-number>
										<span style="color:#999999;margin-left:10px">
											序号越大，排序越靠前
										</span>
									</div>
								);
							}
						}
					},
					{
						prop: 'status',
						label: '商品状态：',
						value: 1,
						component: {
							name: 'g_radio',
							data() {
								return {
									value2: 1
								};
							},
							props: {
								value: [String, Number]
							},
							mounted() {
								this.value2 = Number(this.value || 1);
							},
							methods: {
								change(e) {
									this.$emit('input', e);
								}
							},
							render() {
								return (
									<el-radio-group onChange={this.change} v-model={this.value2}>
										<el-radio label={1}>上架</el-radio>
										<el-radio label={2}>下架</el-radio>
									</el-radio-group>
								);
							}
						}
					}
				],
				op: {
					visible: true,
					layout: ['confirm']
				},
				on: {
					submit({ data, close }) {
						data.appPlatforms = data.appPlatforms.join(',');
						data.quanMLink = self.enterGoodsInfo.quanMLink;
						data.hzQuanOver = self.enterGoodsInfo.hzQuanOver;
						self.$service.goodsMenagement.mdGoods
							.add({
								...data,
								...data.url,
								gid: item.gid,
								startTime: data.time[0],
								endTime: data.time[1],
								isFree: 1,
								type: 0
							})
							.then(() => {
								self.$message({
									message: '设置成功',
									type: 'success'
								});
								self.crud.refresh();
								close();
								return;
							})
							.catch(err => {
								self.$message.error(err);
							});
					}
				}
			});
		},
		onLoad({ ctx, app }) {
			const self = this;
			this.crud = app;
			ctx.service(this.$service.goodsMenagement.jdRank)
				.set('dict', {
					label: {
						add: '录入商品'
					},
					api: {
						info: 'detail'
					}
				})
				.set('table', {
					columns: [
						{
							label: '序号',
							type: 'index',
							align: 'center',
							width: 80
						},
						{
							label: '商品信息',
							prop: 'goodInfo',
							align: 'left',
							'min-width': 400
						},
						{
							label: '优惠券信息',
							prop: 'couponInfo',
							align: 'left',
							'min-width': 350
						},
						// {
						// 	label: '是否首页置顶',
						// 	prop: 'isRecommended',
						// 	align: 'center'
						// },
						// {
						// 	label: '商品排序',
						// 	prop: 'ysqLevel',
						// 	align: 'center',
						// 	sortable: 'custom',
						// 	emptyText: '0',
						// 	'min-width': 100
						// },
						{
							label: '创建时间',
							prop: 'createTime',
							align: 'center',
							'min-width': 150,
							sortable: 'custom'
						},
						{
							label: '更新时间',
							prop: 'updateTime',
							align: 'center',
							'min-width': 150,
							sortable: 'custom'
						},
						{
							label: '历史排名',
							prop: 'ranking',
							align: 'center',
							'min-width': 100,
							sortable: 'custom'
						},
						{
							label: '月销量',
							prop: 'sale',
							align: 'center',
							sortable: 'custom',
							'default-sort': 'descending',
							emptyText: '无',
							'min-width': 100
						},
						{
							label: '佣金比例',
							prop: 'commissionRate',
							align: 'center',
							sortable: 'custom',
							emptyText: '0',
							'min-width': 100
						}
						// {
						// 	label: '9.9包邮',
						// 	prop: 'isNine',
						// 	align: 'center',
						// 	'min-width': 100
						// },
						// {
						// 	label: '抖好货',
						// 	prop: 'isDHh',
						// 	align: 'center',
						// 	'min-width': 100
						// }
						// {
						// 	label: '是否下架',
						// 	prop: 'gStatus',
						// 	align: 'center',
						// 	'min-width': 100
						// },
						// {
						// 	label: '平台',
						// 	prop: 'platform',
						// 	align: 'center',
						// 	'min-width': 100
						// }
					],

					op: {
						props: {
							width: 140
						},
						layout: [
							'slot-setFree',
							'slot-setSort',
							'slot-setBillion',
							'slot-setTime',
							'slot-zero'
						]
					}
				})
				.set('upsert', {
					props: {
						labelWidth: '120px',
						center: true,
						'custom-class': 'custom-class-dialog'
					},
					items: [
						{
							prop: 'pic',
							label: '商品主图：',
							span: 24,
							component: {
								name: 'cl-upload'
							}
						},
						{
							prop: 'title',
							label: '商品标题',
							span: 24,
							component: {
								name: 'el-input',
								attrs: {
									size: 'mini'
								}
							}
						},
						{
							prop: 'url',
							props: {
								labelWidth: '0px'
							},
							// label: '优惠券链接：',
							component: {
								name: 'search-counpon',
								methods: {
									input(e) {
										this.$emit('input', e);
									}
								},
								render() {
									return (
										<searchCounpon
											onInput={this.input}
											item={self.enterGoodsInfo}></searchCounpon>
									);
								}
							},
							rules: [{ required: true, message: '请先检索商品', trigger: 'blur' }]
						},
						{
							prop: 'isNine',
							label: '是否9.9包邮：',
							value: false,
							component: {
								name: 'el-switch'
							}
						},
						{
							prop: 'isFree',
							label: '是否0元购：',
							value: false,
							component: {
								name: 'el-switch'
							}
						},

						{
							prop: 'ysqLevel',
							label: '商品排序：',
							value: 100,
							component: {
								name: 'ysqlevels',
								data() {
									return {
										ysqLevel: 100
									};
								},
								props: {
									value: [String, Number]
								},
								mounted() {
									this.ysqLevel = this.value;
								},
								methods: {
									input(e) {
										this.$emit('input', e);
									}
								},
								render() {
									return (
										<div style="display:flex">
											<el-input-number
												v-model={this.ysqLevel}
												controls-position="right"
												onInput={this.input}
												min={1}
												max={10000}></el-input-number>
											<span style="color:#999999;margin-left:10px">
												序号越大，排序越靠前
											</span>
										</div>
									);
								}
							}
						},
						{
							prop: 'gStatus',
							label: '商品状态：',
							value: 1,
							component: {
								name: 'g_radio',
								data() {
									return {
										value2: 1
									};
								},
								props: {
									value: [String, Number]
								},
								mounted() {
									this.value2 = Number(this.value || 1);
								},
								methods: {
									change(e) {
										this.$emit('input', e);
									}
								},
								render() {
									return (
										<el-radio-group
											onChange={this.change}
											v-model={this.value2}>
											<el-radio label={1}>上架</el-radio>
											<el-radio label={0}>下架</el-radio>
										</el-radio-group>
									);
								}
							}
						},
						{
							prop: 'isRecommended',
							props: {
								'label-width': '120px'
							},
							label: '是否开启首页置顶',
							span: 13,
							value: false,
							component: {
								name: 'el-switch',
								on: {
									change(val) {
										if (val) {
											app.setData(
												'upsert.items[prop:recommendSort].hidden',
												false
											);
										} else {
											app.setData(
												'upsert.items[prop:recommendSort].hidden',
												true
											);
										}
									}
								}
							}
						},
						{
							prop: 'recommendSort',
							label: '商品置顶排序',
							span: 24,
							hidden: true,
							value: 1,
							component: {
								name: 'recommendSort-input',
								data() {
									return {
										value2: 0
									};
								},
								props: {
									value: [String, Number]
								},
								mounted() {
									this.value2 = this.value;
								},
								methods: {
									input(e) {
										this.$emit('input', e);
									}
								},
								render() {
									return (
										<div style="display:flex">
											<el-input-number
												controls-position="right"
												min={1}
												max={5}
												onInput={this.input}
												v-model={this.value2}></el-input-number>
											<span style="color:red;margin-left:10px">
												* 首页置顶(序号越小，排序越靠前)
											</span>
										</div>
									);
								}
							},
							rules: [{ required: true, message: '排序不能为空', trigger: 'blur' }]
						}
					],
					op: {
						visible: true,
						layout: ['confirm']
					}
				})
				.set('layout', [
					['refresh-btn', 'slot-filter', 'query', 'flex1', 'search-key'],
					['data-table'],
					['flex1', 'pagination']
				])
				.on('open', () => {
					app.setData('upsert.items[prop:recommendSort].hidden', true);
				})
				.on('close', isOpen => {
					if (!isOpen) {
						// 清空商品数据
						this.enterGoodsInfo = {};
					}
				})
				.on('submit', (isOpen, data, { next }) => {
					next({
						...data,
						...data.url,
						isFree: data.isFree ? 1 : 0,
						isRecommended: data.isRecommended ? 1 : 0,
						isNine: data.isNine ? 1 : 0,
						gid: this.enterGoodsInfo.gid
					});
				})
				.on('refresh', async (params, { next }) => {
					if (params.isNine === '') {
						delete params.isNine;
					}
					if (params.isDhh === '') {
						delete params.isDhh;
					}
					let { list } = await next(params);
					list.map(item => {
						item.commissionRate = (item.commissionRate || 0) + '%';
						item.sale = item.sale + '件';
					});
				})
				.done();

			app.refresh({
				// gStatus: 1,
				startCouponMoney: 0,
				startSale: 0,
				type: self.params.type
				// order: 'asc',
				// prop: 'endPrice'
			});
		},
		// 录入商品
		addGoods() {
			this.crud.add();
		},
		search() {},
		refresh(data) {
			console.log(data);
			this.crud.refresh({
				...data
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.nav {
	padding: 0 10px;
	font-size: $font12;
	::v-deep .el-input-number.is-controls-right .el-input__inner {
		padding-left: 15px;
		padding-right: 20px;
	}
	::v-deep .el-input-number--mini {
		width: 71px;
	}
	.nav-li {
		margin-right: 20px;
		span {
			color: $text-grey;
			margin-right: 10px;
		}
		.el-select {
			width: 90px;
		}
		.el-input-number--mini {
			width: 100px;
		}
	}
}
.setsort {
	color: $color-link;
	cursor: pointer;
	margin: 5px 5px 5px 15px;
	:hover {
		opacity: 0.8;
	}
}
</style>
